/*
 * Includes
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <minix/endpoint.h>
#include <minix/syslib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "cs_helper.h"

/*
 * Runs the program
 */
int main(int argc, char* argv[]) {
	int errno;
	int comEndpoint;
	register message *msgptr;
	{
		int status;
		char test[20] = "test0 test1 ;";
		msgptr->m_type = INIT_PROC;
		status = _sendrec(PM_PROC_NR, msgptr);
		if (status != 0) {
			printf("Error in sendrec process\n");
		}

		switch (msgptr->m_type) {
		case SEND_ENDPOINT: {
			/*Initialize process*/
			/* get endpoint from com */
			printf("Endpoint from com driver:%d\n", msgptr->RT_DRIVER_ENDPT);
			comEndpoint = msgptr->RT_DRIVER_ENDPT;

		}
			break;
		default: {
			printf("handle process reply: unknown reply type: %d\n",
					msgptr->m_type);
		}
		}

		/*send actions to com driver*/
		msgptr->m_type = INIT_PROC;
		msgptr->RT_DRIVER_ID = 1;
		msgptr->TEST_DATA = &test;
		status = _sendrec(comEndpoint, msgptr);
		if (status != 0) {
			printf("Error in sendrec process\n");
		}
		switch (msgptr->m_type) {
		case INIT_PROC: {
			printf("Reply received from com driver\n");
		}
			break;
		default: {
			printf("handle process reply: unknown reply type: %d\n",
					msgptr->m_type);
		}
		}

	}
	return (msgptr->m_type);
}

